import request from '@/utils/request'

// 获取测试申请单列表
export function getApplicationList(params) {
  return request({
    url: '/api/applications',
    method: 'get',
    params
  })
}

// 获取测试申请单详情
export function getApplicationById(applicationId) {
  return request({
    url: `/api/applications/${applicationId}`,
    method: 'get'
  })
}

// 创建测试申请单
export function createApplication(data) {
  return request({
    url: '/api/applications',
    method: 'post',
    data
  })
}

// 更新测试申请单
export function updateApplication(applicationId, data) {
  return request({
    url: `/api/applications/${applicationId}`,
    method: 'put',
    data
  })
}

// 删除测试申请单
export function deleteApplication(applicationId) {
  return request({
    url: `/api/applications/${applicationId}`,
    method: 'delete'
  })
}

// 提交测试申请单
export function submitApplication(applicationId) {
  return request({
    url: `/api/applications/${applicationId}/submit`,
    method: 'put'
  })
}

// 审批测试申请单
export function approveApplication(applicationId, data) {
  return request({
    url: `/api/applications/${applicationId}/approve`,
    method: 'put',
    data
  })
}

// 拒绝测试申请单
export function rejectApplication(applicationId, data) {
  return request({
    url: `/api/applications/${applicationId}/reject`,
    method: 'put',
    data
  })
}

// 测试负责人审批通过申请单
export function testManagerApprove(applicationId, data) {
  return request({
    url: `/api/applications/${applicationId}/manager-approve`,
    method: 'put',
    data
  })
}

// 测试负责人审批拒绝申请单
export function testManagerReject(applicationId, data) {
  return request({
    url: `/api/applications/${applicationId}/manager-reject`,
    method: 'put',
    data
  })
}

// 取消测试申请单
export function cancelApplication(applicationId, data) {
  return request({
    url: `/api/applications/${applicationId}/cancel`,
    method: 'put',
    data
  })
}

// 获取申请单关联的测试任务
export function getApplicationTasks(applicationId, params) {
  return request({
    url: `/api/applications/${applicationId}/tasks`,
    method: 'get',
    params
  })
}

// 获取申请单附件列表
export function getApplicationAttachments(applicationId) {
  return request({
    url: `/api/applications/${applicationId}/attachments`,
    method: 'get'
  })
}

// 上传申请单附件
export function uploadApplicationAttachment(applicationId, formData) {
  return request({
    url: `/api/applications/${applicationId}/attachments`,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除申请单附件
export function deleteApplicationAttachment(applicationId, attachmentId) {
  return request({
    url: `/api/applications/${applicationId}/attachments/${attachmentId}`,
    method: 'delete'
  })
}

// 下载申请单附件
export function downloadApplicationAttachment(applicationId, attachmentId) {
  return request({
    url: `/api/applications/${applicationId}/attachments/${attachmentId}/download`,
    method: 'get',
    responseType: 'blob'
  })
}

// 获取申请单历史记录
export function getApplicationHistory(applicationId) {
  return request({
    url: `/api/applications/${applicationId}/history`,
    method: 'get'
  })
}